﻿Imports Darkorbit
Imports Darkorbit.Const
Imports System.Threading

Public Class AccountControl
    Private _Account As Account

    Public Property Account As Account
        Get
            Return _Account
        End Get
        Set(value As Account)
            _Account = value
        End Set
    End Property

    Sub New(ByVal Account As Account)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        _Account = Account
    End Sub

    Sub mybase_Load() Handles MyBase.Load
        With New Thread(AddressOf refreshUserData)
            .IsBackground = True
            .Start()
            While .IsAlive
                Application.DoEvents()
            End While
        End With
        tmrRefreshUserData.Enabled = True
    End Sub

    Sub refreshUserData()
        Dim cre As Integer = _Account.getCredits()
        Dim uri As Integer = _Account.getUridium()
        Dim ses As String = _Account.getSessionId()
        Invoke(Sub()
                   lblUsername.Text = "&Username: " & _Account.Username
                   lblServer.Text = "&Server: " & _Account.Server
                   lblUserId.Text = "&UserId: " & _Account.UserId
                   lblCredits.Text = "&Credits: " & cre.ToString
                   lblSessionId.Text = "&SessionId: " & ses
                   lblUridium.Text = "&Uridium: " & uri.ToString
               End Sub)

    End Sub

#Region "SpinGG"
    Private Sub cmdSpinGalaxyGate_Click(sender As Object, e As EventArgs) Handles cmdSpinGalaxyGate.Click
        Dim gateId As Integer = 0
        Select Case cmbGalaxyGates.Text
            Case "Alpha"
                gateId = GalaxyGates.ALPHA
            Case "Beta"
                gateId = GalaxyGates.BETA
            Case "Gamma"
                gateId = GalaxyGates.GAMMA
            Case "Delta"
                gateId = GalaxyGates.DELTA
            Case "Epsilon"
                gateId = GalaxyGates.EPSILON
            Case "Zeta"
                gateId = GalaxyGates.ZETA
            Case "Kappa"
                gateId = GalaxyGates.KAPPA
            Case "Lambda"
                gateId = GalaxyGates.LAMBDA
            Case "Hades"
                gateId = GalaxyGates.HADES
        End Select
        With New Thread(New ParameterizedThreadStart(AddressOf spinGGAsync))
            .IsBackground = True
            .Start(New Object() {gateId, cmbGalaxyGates.Text, nudGalaxyGateSpins.Value})
        End With
    End Sub

    Sub spinGGAsync(ByVal arr As Object())
        _Account.spinGalaxyGate(CInt(arr(0)), CStr(arr(1)), CInt(arr(2)))
    End Sub
#End Region

    Private Sub tmrRefreshUserData_Tick(sender As Object, e As EventArgs) Handles tmrRefreshUserData.Tick
        With New Thread(AddressOf refreshUserData)
            .IsBackground = True
            .Start()
            While .IsAlive
                Application.DoEvents()
            End While
        End With
    End Sub
    Dim upgradeSkylab As Boolean = False
    Private Sub cmdSkylab_Click(sender As Object, e As EventArgs) Handles cmdSkylab.Click
        If UpgradeSkylab = False Then
            cmdSkylab.Text = "Stop"
            UpgradeSkylab = True
        Else
            cmdSkylab.Text = "Start"
            UpgradeSkylab = False
        End If
    End Sub

    Private Sub tmrUpgradeSkylab_Tick(sender As Object, e As EventArgs) Handles tmrUpgradeSkylab.Tick
        If UpgradeSkylab Then
            For Each item In lbSkylabItems.Items
                If item.Checked Then
                    Select Case item.Text
                        Case "Terbiumcollector"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.TERBIUMCOLLECTOR)
                                            End Sub)
                            End With

                        Case "Enduriumcollector"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.ENDURIUMCOLLECTOR)
                                            End Sub)
                            End With
                        Case "Prometiumcollector"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.PROMETIUMCOLLECTOR)
                                            End Sub)
                            End With
                        Case "Solarmodule"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.SOLARMODULE)
                                            End Sub)
                            End With
                        Case "Storagemodule"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.STORAGEMODULE)
                                            End Sub)
                            End With
                        Case "Basemodule"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.BASEMODULE)
                                            End Sub)
                            End With
                        Case "Xenomodule"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.XENOMODULE)
                                            End Sub)
                            End With
                        Case "Sepromrefinery"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.SEPROMREFINERY)
                                            End Sub)
                            End With
                        Case "Promeriumrefinery"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.PROMERIUMREFINERY)
                                            End Sub)
                            End With
                        Case "Duraniumrefinery"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.DURANIUMREFINERY)
                                            End Sub)
                            End With
                        Case "Prometidrefinery"
                            With New Thread(Sub()
                                                _Account.upgradeSkylab(SkylabConstruction.PROMETIDREFINERY)
                                            End Sub)
                            End With
                    End Select
                End If
            Next
        End If
    End Sub


    Dim upgradeTechCenter As Boolean = False
    Private Sub cmdUpgradeTechCenter_Click(sender As Object, e As EventArgs) Handles cmdUpgradeTechCenter.Click
        If upgradeTechCenter = False Then
            cmdUpgradeTechCenter.Text = "Stop"
            upgradeTechCenter = True
        Else
            cmdUpgradeTechCenter.Text = "Start"
            upgradeTechCenter = False
        End If
    End Sub

    Private Sub tmrUpgradeTechcenter_Tick(sender As Object, e As EventArgs) Handles tmrUpgradeTechcenter.Tick
        If upgradeSkylab Then
            Select Case cmbTechCenterSlot1.Text
                Case "Energyleecher"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.ENERGYLEECHER, 1)
                                    End Sub)
                    End With
                Case "Chainimpulse"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.CHAINIMPULSE, 1)
                                    End Sub)
                    End With
                Case "Precisiontargeter"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.PRECISIONTARGETER, 1)
                                    End Sub)
                    End With
                Case "Shieldbackup"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.SHIELDBACKUP, 1)
                                    End Sub)
                    End With
                Case "Battlerepairbot"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.BATTLEREPAIRBOT, 1)
                                    End Sub)
                    End With
            End Select

            Select Case cmbTechCenterSlot2.Text
                Case "Energyleecher"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.ENERGYLEECHER, 2)
                                    End Sub)
                    End With
                Case "Chainimpulse"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.CHAINIMPULSE, 2)
                                    End Sub)
                    End With
                Case "Precisiontargeter"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.PRECISIONTARGETER, 2)
                                    End Sub)
                    End With
                Case "Shieldbackup"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.SHIELDBACKUP, 2)
                                    End Sub)
                    End With
                Case "Battlerepairbot"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.BATTLEREPAIRBOT, 2)
                                    End Sub)
                    End With
            End Select

            Select Case cmbTechCenterSlot3.Text
                Case "Energyleecher"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.ENERGYLEECHER, 3)
                                    End Sub)
                    End With
                Case "Chainimpulse"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.CHAINIMPULSE, 3)
                                    End Sub)
                    End With
                Case "Precisiontargeter"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.PRECISIONTARGETER, 3)
                                    End Sub)
                    End With
                Case "Shieldbackup"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.SHIELDBACKUP, 3)
                                    End Sub)
                    End With
                Case "Battlerepairbot"
                    With New Thread(Sub()
                                        _Account.buildTechCenter(TechfactoryItem.BATTLEREPAIRBOT, 3)
                                    End Sub)
                    End With
            End Select

        End If

    End Sub

End Class
